var base64 = require("../weui/example/images/base64");
//获取应用实例
const app = getApp()

Page({
  data: {
    imageArr: [],
    indicatorDots: false,
    vertical: true,
    autoplay: true,
    interval: 2000,
    duration: 500,
    userId: null,
    notice4Arr: [],
    pageNo: 1,
    pageSize: 5,
    wh:0
  },
  onLoad: function () {
    var that = this;
    this.setData({
      icon20: base64.icon20,
      icon60: base64.icon60
    });
    if (app.globalData.userId) {
      this.setData({
        userId: app.globalData.userId
      })
    } 
    wx.request({
      url: 'https://www.xinhuo.site/api/ads/list',
      data: {
        adsType: 3
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          that.data.imageArr = res.data.recordList
          that.setData({
            imageArr: that.data.imageArr
          })
        }
      }
    })
    wx.request({
      url: 'https://www.xinhuo.site/api/notice/list',
      data: {
        pageNo: this.data.pageNo,
        pageSize: this.data.pageSize,
        noticeType: 4
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          that.data.notice4Arr = that.data.notice4Arr.concat(res.data.recordList)
          that.setData({
            notice4Arr: that.data.notice4Arr
          })
        }
      }
    })
  },
  onPullDownRefresh: function () {
    var that = this;
    wx.request({
      url: 'https://www.xinhuo.site/api/notice/list',
      data: {
        pageNo: this.data.pageNo,
        pageSize: this.data.pageSize,
        noticeType: 4
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          that.data.notice4Arr = res.data.recordList
          that.setData({
            notice4Arr: that.data.notice4Arr
          })
        }
        wx.stopPullDownRefresh({
        })
      }
    })
  },
  onShow: function () {
    var that = this;
    if (app.globalData.userId != null) {
      this.setData({
        userId: app.globalData.userId
      });
    }
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          "wh": res.windowHeight + 200
        })
      }
    })
  },
  moreInfo4: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../noticeList/noticeList?noticeType=4'
    })
  },
  toMeeting: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../meeting/meeting'
    })
  },
  toGuiding: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../guidingType/guidingType'
    })
  },
  toCertificate: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../certificate/certificate'
    })
  },
  toAbroad: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../abroad/abroad'
    })
  },
  toReduction: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../reduction/reduction'
    })
  },
  toNotice: function (e) {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../noticeDetail/noticeDetail?id=' + e.currentTarget.dataset.id
    })
  },
  toActivities: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../activities/activities'
    })
  },
  toCostBase: function(){
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../costbase/costbase'
    })
  },
  noContent1: function () {
    wx.navigateTo({
      url: '../404/noContent?pageType=规定动作'
    })
  },
  noContent2: function () {
    wx.navigateTo({
      url: '../404/noContent?pageType=我的待办'
    })
  }
})
